package cc.atliberty.creating.abstractfactory.abstractfactory2;

public class ProduceFactory {
    public static AbstractFactory getFactory(String witch) {
        AbstractFactory af = null;
        String packageName = ProduceFactory.class.getPackage().getName();
        StringBuilder sb = new StringBuilder();
        sb.append(packageName);
        sb.append(".");
        sb.append(Character.toUpperCase(witch.charAt(0)));
        sb.append(witch.substring(1));
        try {
            af = (AbstractFactory) Class.forName(sb.toString()).newInstance();
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            e.printStackTrace();
        }
        return af;
    }
}
